#include<bits/stdc++.h>
#define mpr make_pair
#define sz(x) (int)(x.size())
using namespace std;
typedef long long ll;
const int inf=2e9;
const int MAXN=200005;
int n;
int v[MAXN];
void solve(){
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(ll i=0;i<(1<<n);i++){
        ll res=0;
        ll k=i;
        vector<int> p;
        while(k!=0){
            p.push_back(k%2);
            k/=2;
        }
        reverse(p.begin(),p.end());
        int red=0,blue=0;
        for(int i=0;i<sz(p);i++){
            if(p[i]==1){
                //red
                if(red==0) red=v[i];
                else if(red==v[i]){
                    res+=red;
                }else{
                    red=v[i];
                }
            }else{
                //blue
                if(blue==0) blue=v[i];
                else if(blue==v[i]){
                    res+=blue;
                }else{
                    blue=v[i];
                }
            }
        }
        ans=max(ans,res);
    }
    cout<<ans<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int tt;
    cin>>tt;
    while(tt--){
        solve();
    }
    return 0;
}